/*MASTER- Santa Clara Homelessness Prevention
	*Last Updated: 2023-05-10
	*Last Updated By: David Phillips
	*
	*Directions: edit the directory commands on lines 14-22 and then run this do file
	*
*/		

	log using scc_hp_replication.log, replace


	***
	***Set directories
	***
	
		*location of replication code
		*global mydir "D:\Shared drives\LEO-Everyone-Write\Projects\Santa Clara County (SCC) - Homelessness Prevention\7. Research\Journal Submissions\RESTAT\replication_package"
		global mydir "H:\Shared drives\LEO-Everyone-Write\Projects\Santa Clara County (SCC) - Homelessness Prevention\7. Research\Journal Submissions\RESTAT\replication_package"
		*location of confidential data
		global datadir "Z:\SCC RCT\De-Identified\data"
		*location of large Infutor matched file
		global rawdir "Z:/SCC RCT/Raw-Data"
		*location for output
		global outputdir "C:\Users\dphill12\Downloads"
		

	***
	***Parameters 
	***

		clear 
		set more off
		cap log close
		set seed 1373312019
		
		global graphs 1 /*switch to 0 if graphs not wanted*/ 
		global makeinfutor 0 /*switch to 1 if remaking infutor extract*/

		*set global directories and variable lists
		do "$mydir\0_globals.do"
		
		*prep for output
		cd "$outputdir"
	
		*package installs
		cap ssc install estout
		cap ssc install coefplot
		cap ssc install cibar

		*making output sub-folders
		cap mkdir "${outputdir}/Tables"	
		cap mkdir "${outputdir}/Figures"	
	
	***
	*** Processing raw data
	***
	
		*process assesment data; turn into one record per person; RCT or first observed
		do "$mydir/1_1_assessments.do"

		*create file of HMIS program outcomes
		do "$mydir/1_2_enrollments.do"
		
		*create lagged outcomes for balance table
		do "$mydir/1_3_lagged"

		*create file of Infutor outcomes
			* NOTE: this code requires access to raw Infutor data, which must be purchased from Infutor, 
			*		and the identifiable HMIS extract which is only accessible to Santa Clara County
			*		so the replication data at SCC simply includes its post-match output, inf_scc_fuzzymatch_final HP 2.2.2022.dta
 			if $makeinfutor == 1 {
				*code run using national Infutor data
				do "$mydir/inf_make_extract.do"
				do "$mydir/inf_append_states_together.do"
				do "$mydir/inf_processing_extract_20211203.do"
				*code run at Santa Clara County
				do "$mydir/infutor_matcher_scc_20211203.do"
			}

			do "$mydir/1_4_infutor.do"
 	
		*assistance amounts
		do "$mydir/1_5_payments"
	
	
	***
	*** Combine files into analysis dataset
	***
		do "$mydir/2_datamaker.do"
	
	***
	*** Analysis
	***
	
		*main tables and graphs
		do "$mydir/3_1_analysis.do"

		*heterogeneous effects
		do "$mydir/3_2_het.do"
	
	
	
	log close